#pragma once

#include "Head.h"
#include "DeviceMgr.h"

namespace Geometry 
{
	//class _declspec(dllexport) Rect2
	//{
	//	Vertex2 m_vertices[4];
	//	std::string m_textureFile;
	//	IDirect3DTexture9* m_pTexture;
	//public:
	//	Rect2(int x, int y, int w, int h, std::string texName)
	//	{
	//		m_pTexture = NULL;
	//		m_textureFile = texName;
	//		m_vertices[0].x = x;
	//		m_vertices[0].y = y;
	//		m_vertices[0].color = D3DCOLOR_ARGB(127, 255, 255, 255);
	//		m_vertices[0].u = 0.02f;
	//		m_vertices[0].v = 0.03f;

	//		m_vertices[1].x = x + w;
	//		m_vertices[1].y = y;
	//		m_vertices[1].color = D3DCOLOR_ARGB(127, 255, 255, 255);
	//		m_vertices[1].u = 0.98f;
	//		m_vertices[1].v = 0.03f;

	//		m_vertices[2].x = x + w;
	//		m_vertices[2].y = y + h;
	//		m_vertices[2].color = D3DCOLOR_ARGB(127, 255, 255, 255);
	//		m_vertices[2].u = 0.98f;
	//		m_vertices[2].v = 0.97f;

	//		m_vertices[3].x = x;
	//		m_vertices[3].y = y + h;
	//		m_vertices[3].color = D3DCOLOR_ARGB(127, 255, 255, 255);
	//		m_vertices[3].u = 0.02f;
	//		m_vertices[3].v = 0.97f;

	//		m_vertices[0].z = m_vertices[1].z = m_vertices[2].z = m_vertices[3].z = 0.0f;
	//		m_vertices[0].w = m_vertices[1].w = m_vertices[2].w = m_vertices[3].w = 1.0f;
	//	}

	//	void DrawRect2(DX::DirectX& mgr)
	//	{
	//		IDirect3DDevice9* dev = mgr.GetDevice();
	//		if(m_pTexture == NULL)
	//		{
	//			D3DXCreateTextureFromFile(dev, "border.jpg", &m_pTexture);
	//		}
	//	
	//		dev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
	//		dev->SetTexture(0, m_pTexture);
	//		dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, m_vertices, sizeof(Vertex2));
	//		dev->SetTexture(0, NULL);

	//	}
	//};


	//class _declspec(dllexport) Rect
	//{
	//	VertexTexture m_vertices[4];
	//	IDirect3DTexture9* m_pTexture;
	//	float m_rotation;
	//public:
	//	Rect(int x, int y, int w, int h)
	//	{
	//		m_rotation = 0.0f;
	//		m_pTexture = NULL;

	//		m_vertices[0].x = x;
	//		m_vertices[0].y = y;
	//		m_vertices[0].color = D3DCOLOR_ARGB(127, 255, 255, 255);
	//		m_vertices[0].u = 0.0f;
	//		m_vertices[0].v = 0.0f;

	//		m_vertices[1].x = x + w;
	//		m_vertices[1].y = y;
	//		m_vertices[1].color = D3DCOLOR_ARGB(127, 255, 255, 255);
	//		m_vertices[1].u = 1.0f;
	//		m_vertices[1].v = 0.0f;

	//		m_vertices[2].x = x + w;
	//		m_vertices[2].y = y + h;
	//		m_vertices[2].color = D3DCOLOR_ARGB(127, 255, 255, 255);
	//		m_vertices[2].u = 1.0f;
	//		m_vertices[2].v = 1.0f;

	//		m_vertices[3].x = x;
	//		m_vertices[3].y = y + h;
	//		m_vertices[3].color = D3DCOLOR_ARGB(127, 255, 255, 255);
	//		m_vertices[3].u = 0.0f;
	//		m_vertices[3].v = 1.0f;

	//		m_vertices[0].z = m_vertices[1].z = m_vertices[2].z = m_vertices[3].z = 0.0f;
	//	}

	//	void DrawRect(DX::DirectX& mgr)
	//	{
	//		IDirect3DDevice9* dev = mgr.GetDevice();
	//		if(m_pTexture == NULL)
	//		{
	//			D3DXCreateTextureFromFile(dev, "fire.png", &m_pTexture);
	//		}

	//		m_rotation += 1.0f;
	//		if(m_rotation > 360.0f)
	//			m_rotation -= 360.0f;
	//		D3DXMATRIX matRot;
	//		D3DXMatrixRotationY(&matRot, D3DXToRadian(m_rotation));
	//		dev->SetTransform(D3DTS_WORLD, &matRot);

	//		dev->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
	//		dev->SetTexture(0, m_pTexture);
	//		dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, m_vertices, sizeof(VertexTexture));
	//		dev->SetTexture(0, NULL);

	//		D3DXMatrixIdentity(&matRot);
	//		dev->SetTransform(D3DTS_WORLD, &matRot);
	//	}
	//};

	class _declspec(dllexport) Triangle
	{
	private:
		Vertex m_vertices[3];
		float m_alpha;
		bool m_decrease;

	public:
		Triangle(int x, int y, int width, int height)
		{
			m_decrease = true;
			m_alpha = 255.0f;
			m_vertices[0].x = x;
			m_vertices[0].y = y;
			m_vertices[0].color = D3DCOLOR_ARGB((int)m_alpha, 255, 0, 0);

			m_vertices[1].x = x + width;
			m_vertices[1].y = y;
			m_vertices[1].color = D3DCOLOR_ARGB((int)m_alpha, 0, 255, 0);

			m_vertices[2].x = x + width / 2;
			m_vertices[2].y = y + height;
			m_vertices[2].color = D3DCOLOR_ARGB((int)m_alpha, 0, 0, 255);

			m_vertices[0].z = m_vertices[1].z = m_vertices[2].z = 0.0f;
		}

		void DrawTriangle(DX::DirectX& mgr)
		{
			if(m_decrease)
			{
				m_alpha -= 0.8f;
				if(m_alpha < 0)
				{
					m_alpha *= -1.0f;
					m_decrease = false;
				}
			}
			else
			{
				m_alpha += 0.8f;
				if(m_alpha > 255.0f)
				{
					m_alpha = 510.0f - m_alpha;
					m_decrease = true;
				}
			}

			m_vertices[0].color = D3DCOLOR_ARGB((int)m_alpha, 255, 0, 0);
			m_vertices[1].color = D3DCOLOR_ARGB((int)m_alpha, 0, 255, 0);
			m_vertices[2].color = D3DCOLOR_ARGB((int)m_alpha, 0, 0, 255);

			IDirect3DDevice9* dev = mgr.GetDevice();
			dev->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
			dev->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, m_vertices, sizeof(Vertex));
		}
	};
}